﻿'以下代码由 Microsoft Visual Studio 2005 生成。
'测试所有者应该检查每个测试的有效性。
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports System
Imports System.Text
Imports System.Collections.Generic
Imports GConverter = Converter






'''<summary>
'''这是 Converter.Converter 的测试类，旨在
'''包含所有 Converter.Converter 单元测试
'''</summary>
<TestClass()> _
Public Class ConverterTest


    Private testContextInstance As TestContext

    '''<summary>
    '''获取或设置测试上下文，上下文提供
    '''有关当前测试运行及其功能的信息。
    '''</summary>
    Public Property TestContext() As TestContext
        Get
            Return testContextInstance
        End Get
        Set(ByVal value As TestContext)
            testContextInstance = value
        End Set
    End Property
#Region "附加测试属性"
    '
    '编写测试时，可使用以下附加属性:
    '
    '使用 ClassInitialize 在运行类中的第一个测试前先运行代码
    '
    '<ClassInitialize()>  _
    'Public Shared Sub MyClassInitialize(ByVal testContext As TestContext)
    'End Sub
    '
    '使用 ClassCleanup 在运行完类中的所有测试后再运行代码
    '
    '<ClassCleanup()>  _
    'Public Shared Sub MyClassCleanup()
    'End Sub
    '
    '使用 TestInitialize 在运行每个测试前先运行代码
    '
    '<TestInitialize()>  _
    'Public Sub MyTestInitialize()
    'End Sub
    '
    '使用 TestCleanup 在运行完每个测试后运行代码
    '
    '<TestCleanup()>  _
    'Public Sub MyTestCleanup()
    'End Sub
    '
#End Region


    '''<summary>
    '''Convert(ByVal System.Text.Encoding, ByVal System.Text.Encoding, ByVal String) 的测试
    '''</summary>
    <TestMethod()> _
    Public Sub ConvertTest()
        Dim srcEncoding As Encoding = Encoding.GetEncoding(932)

        Dim dstEncoding As Encoding = Encoding.GetEncoding(65001)


        Dim bytes(3) As Byte
        bytes(0) = 148
        bytes(1) = 233
        bytes(2) = 150
        bytes(3) = 167


        Dim str As String = srcEncoding.GetString(bytes)

        Dim expected(5) As Byte
        expected(0) = 231
        expected(1) = 167
        expected(2) = 152
        expected(3) = 229
        expected(4) = 175
        expected(5) = 134


        'Dim expected As String = "秘密"  ' dstEncoding.GetString(b)
        Dim actual As Byte()

        actual = Converter.Converter.Convert(srcEncoding, dstEncoding, str)

        'Assert.AreSame(expected, actual, "Converter.Converter.Convert 未返回所需的值。")
        Assert.AreEqual(expected(0), actual(0), "Converter.Converter.Convert 未返回所需的值。")

    End Sub

    '''<summary>
    '''ToSimplifiedChinese(ByVal String) 的测试
    '''</summary>
    <TestMethod()> _
    Public Sub ToSimplifiedChineseTest()
        Dim str As String = "開"

        Dim expected As String = "开"
        Dim actual As String

        actual = Converter.Converter.ToSimplifiedChinese(str)

        Assert.AreEqual(expected, actual, "Converter.Converter.ToSimplifiedChinese 未返回所需的值。")

    End Sub

    '''<summary>
    '''ToTraditionalChinese(ByVal String) 的测试
    '''</summary>
    <TestMethod()> _
    Public Sub ToTraditionalChineseTest()
        Dim str As String = "开"

        Dim expected As String = "開"
        Dim actual As String

        actual = Converter.Converter.ToTraditionalChinese(str)

        Assert.AreEqual(expected, actual, "Converter.Converter.ToTraditionalChinese 未返回所需的值。")

    End Sub

    '''<summary>
    '''New(ByVal Converter.ConvertMode) 的测试
    '''</summary>
    <Priority(1)> <TestMethod()> _
    Public Sub ConstructorReadModeTest()
        Dim mode As GConverter.ConvertMode = Converter.ConvertMode.Read

        Dim target As GConverter.Converter = New GConverter.Converter(mode)


        Assert.IsNotNull(target, "阅读模式创建失败")

    End Sub
    '''<summary>
    '''New(ByVal Converter.ConvertMode) 的测试
    '''</summary>
    <Priority(2)> <TestMethod()> _
    Public Sub ConstructorCodeTest()
        Dim mode As GConverter.ConvertMode = Converter.ConvertMode.Converting

        Dim target As GConverter.Converter = New GConverter.Converter(mode)


        Assert.IsNotNull(target, "转换模式创建失败")

    End Sub


    '''<summary>
    '''New(ByVal String) 的测试
    '''</summary>
    <Priority(3)> <TestMethod()> _
    Public Sub ConstructorFileTest()
        Dim filename As String = "e:\My Documents\Visual Studio 2005\Projects\Converter\TestConverter\test.txt"

        Dim target As GConverter.Converter = New GConverter.Converter(filename)


        Assert.IsNotNull(target, "文件模式创建失败")
    End Sub

    '''<summary>
    '''Convert() 的测试,阅读模式
    '''</summary>
    <Priority(4)> <TestMethod()> _
    Public Sub ConvertReadTest()
        Dim mode As GConverter.ConvertMode = Converter.ConvertMode.Read

        Dim target As GConverter.Converter = New GConverter.Converter(mode)
        Dim bytes(3) As Byte
        bytes(0) = 148
        bytes(1) = 233
        bytes(2) = 150
        bytes(3) = 167

        Dim srcEncoding As Encoding = Encoding.GetEncoding(932)

        target.SourceEncoding = srcEncoding
        ' target.SourceString = "abd"

        target.SourceString = Encoding.Default.GetString(bytes)

        target.Convert()
        Dim expected As String = "秘密"
        Dim actual As String = target.DestinationString

        '        actual = Converter.Converter.Convert(srcEncoding, dstEncoding, Str)
        Assert.AreEqual(expected, actual, "阅读模式测试失败")

    End Sub
    '''<summary>
    '''Convert() 的测试,阅读模式  异常测试
    '''</summary>
    <Priority(5)> <TestMethod(), ExpectedException(GetType(Exception), "ERROR no Source Text")> _
    Public Sub ConvertReadExceptionTest()
        Dim mode As GConverter.ConvertMode = Converter.ConvertMode.Read

        Dim target As GConverter.Converter = New GConverter.Converter(mode)
        target.Convert()

        'Assert.Fail("阅读模式  异常测试失败")


    End Sub
    '''<summary>
    '''Convert() 的测试,阅读模式  异常测试
    '''</summary>
    <Priority(6)> <TestMethod(), ExpectedException(GetType(Exception), "阅读模式  异常测试失败")> _
    Public Sub ConvertReadExceptionTest2()
        Dim mode As GConverter.ConvertMode = Converter.ConvertMode.Read

        Dim target As GConverter.Converter = New GConverter.Converter(mode)

        target.SourceString = "abc"
        target.Convert()

        'Assert.Fail("阅读模式  异常测试失败")


    End Sub
   
    '''<summary>
    '''Convert() 的测试
    '''</summary>
    <Priority(7)> <TestMethod()> _
    Public Sub ConvertCodeTest()
        Dim mode As GConverter.ConvertMode = Converter.ConvertMode.Converting

        Dim target As GConverter.Converter = New GConverter.Converter(mode)


        target.SourceEncoding = Encoding.GetEncoding(65001)
        target.SourceString = "秘密"
        Dim bytes(3) As Byte
        bytes(0) = 148
        bytes(1) = 233
        bytes(2) = 150
        bytes(3) = 167

        Dim dstEncoding As Encoding = Encoding.GetEncoding(932)
        target.DestinationEncoding = dstEncoding

        target.Convert()
        Dim expected As String = Encoding.UTF8.GetString(bytes)
        Dim actual As String = target.DestinationString

        '        actual = Converter.Converter.Convert(srcEncoding, dstEncoding, Str)
        Assert.AreEqual(expected, actual, "内码转换测试失败")
    End Sub
    '''<summary>
    '''Convert() 的测试 异常测试
    '''</summary>
    <Priority(8)> <TestMethod(), ExpectedException(GetType(Exception), "未设置目标类型异常没有产生")> _
    Public Sub ConvertCodeExceptionTest()
        Dim mode As GConverter.ConvertMode = Converter.ConvertMode.Converting

        Dim target As GConverter.Converter = New GConverter.Converter(mode)


        target.SourceEncoding = Encoding.GetEncoding(65001)
        target.SourceString = "秘密"
        Dim bytes(3) As Byte
        bytes(0) = 148
        bytes(1) = 233
        bytes(2) = 150
        bytes(3) = 167

        target.Convert()

    End Sub
    '''<summary>
    '''Convert() 的测试
    '''</summary>
    <Priority(9)> <TestMethod()> _
    Public Sub ConvertFileTest()
        Dim target As GConverter.Converter = New GConverter.Converter("e:\My Documents\Visual Studio 2005\Projects\Converter\TestConverter\test.txt")
        target.SourceEncoding = Encoding.GetEncoding(932)
        target.Convert()

        Dim expected As String = "秘密"
        Dim actual As String = target.DestinationString


        Assert.AreEqual(expected, actual, "文件模式测试失败")
    End Sub


    '''<summary>
    '''SimplifiedChinese() 的测试
    '''</summary>
    <Priority(10)> <TestMethod()> _
    Public Sub SimplifiedChineseTest()
        Dim mode As GConverter.ConvertMode = Converter.ConvertMode.Read

        Dim target As GConverter.Converter = New GConverter.Converter(mode)

        target.SourceString = "秨"
        target.SourceEncoding = Encoding.GetEncoding(950) '950 Big5



        target.SimplifiedChinese = True

        target.Convert()


        Dim expected As String = "开"
        Dim actual As String

        actual = target.DestinationString

        Assert.AreEqual(expected, actual, "未能转换成简体中文")


    End Sub

    '''<summary>
    '''TraditionalChinese() 的测试
    '''</summary>
    <Priority(11)> <TestMethod()> _
    Public Sub TraditionalChineseTest()
        Dim mode As GConverter.ConvertMode = Converter.ConvertMode.Read

        Dim target As GConverter.Converter = New GConverter.Converter(mode)

        target.SourceString = "秨"
        target.SourceEncoding = Encoding.GetEncoding(950) '950 Big5



        target.TraditionalChinese = True
        target.Convert()


        Dim expected As String = "開"
        Dim actual As String

        actual = target.DestinationString

        Assert.AreEqual(expected, actual, "未能转换成繁体中文")
    End Sub
End Class
